const util = require('util');
const debug = util.debuglog('oil-game:box:action');

//增加金币
exports.addCoins = function (session, coins) {
    let {uid} = session;
    debug("uid = %s  coins = %s 增加金币", uid, coins);
    return new Promise((resolve, reject) => {
        this.app.rpc.login.loginRemote.addCoins(session, uid, session.frontendId, coins, true, function (err, data) {
            if (err) {
                debug("uid = %s  coins = %s 增加金币异常  %s", uid, coins, JSON.stringify(err));
                return reject(err);
            }
            debug("uid = %s  coins = %s 增加金币成功，结果为 %s", uid, coins, JSON.stringify(data));
            resolve(data);
        });
    });
}

//增加石油
exports.addOil = function (session, changeNum) {
    let {uid, frontendId} = session;
    debug("uid = %s  frontendId = %s  changeNum = %s 增加石油", uid, frontendId, changeNum);
    return new Promise((resolve, reject) => {
        this.app.rpc.login.loginRemote.addOil(session, uid, frontendId, changeNum, "box", '', function (err, data) {
            if (err) {
                debug("uid = %s  增加石油异常  %s", uid, JSON.stringify(err));
                return reject(err);
            }
            debug("uid = %s  增加石油成功，结果为 %s", uid, JSON.stringify(data));
            resolve(data);
        });
    });
}

//采集收入加速
exports.addIncomeRate = function (session, changeNum) {
    let {uid, frontendId} = session;
    debug("uid = %s  frontendId = %s  changeNum = %s 采集收入加速", uid, frontendId, changeNum);
    return new Promise((resolve, reject) => {
        this.app.rpc.upgrade.upgradeRemote.openDoubleReward(session, uid, frontendId, changeNum, function (err, data) {
            if (err) {
                debug("uid = %s  增加采集加速异常  %s", uid, JSON.stringify(err));
                return reject(err);
            }
            debug("uid = %s  增加采集加速成功，结果为 %s", uid, JSON.stringify(data));
            resolve(data);
        });
    });
}
